package net.caixiaomi.info.shopkeeper;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;

import net.caixiaomi.info.R;
import net.caixiaomi.info.life.BaseDialog;
import net.caixiaomi.info.model.BaseCallModel;
import net.caixiaomi.info.net.RequestService;
import net.caixiaomi.info.net.ResponseCallback;
import net.caixiaomi.info.net.ResponseError;
import net.caixiaomi.info.net.RetrofitManage;
import net.caixiaomi.info.shopkeeper.entity.ShopDetailMainEntity;
import net.caixiaomi.info.util.ToastUtil;

import retrofit2.Call;

/**
 * Created by mac on 2018/11/19.
 */

public class ShopFailureDialog extends BaseDialog implements View.OnClickListener{

    private TextView mEnsureTv;
    private TextView mCancleTv;
    private TextView mHintTv;
    private EditText mEdite;
    private ShopDetailMainEntity mEntity;
    private callBack callBack;

    public ShopFailureDialog(@NonNull Context context,callBack callBack) {
        super(context);
        this.callBack=callBack;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shop_failure_layout);
        setCanceledOnTouchOutside(true);
        setGravity(Gravity.CENTER,23,0);
        mEnsureTv=findViewById(R.id.shop_failure_ensure);
        mCancleTv=findViewById(R.id.shop_failure_cancle);
        mHintTv=findViewById(R.id.shop_failure_hint);
        mEdite=findViewById(R.id.shop_failure_edite);
        mEnsureTv.setOnClickListener(this);
        mCancleTv.setOnClickListener(this);
        mEdite.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if(!TextUtils.equals("",charSequence)){
                    mHintTv.setVisibility(View.GONE);
                }else{
                    mHintTv.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.shop_failure_ensure:
                callBack.failure(mEdite.getText().toString().trim());
                dismiss();
                break;
            case R.id.shop_failure_cancle:
                dismiss();
                break;
        }
    }

    public interface callBack{
        public void failure(String failMsg);
    }
}
